package com.xxg.renrenuser.apiimpl;

import com.xxg.renrencommon.api.UserManager;
import com.xxg.renrenuser.dao.ExpressAddressInfoDao;
import com.xxg.renrenuser.dao.bean.ExpressAddressInfo;
import lombok.AllArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 类说明
 *
 * @author szj
 * @date 2021/12/13
 */
@DubboService(version = "1.0.0")
@Service
@AllArgsConstructor
public class UserManagerImpl implements UserManager {

    private final ExpressAddressInfoDao expressAddressInfoDao;

    @Override
    public List<String> getUserDefaultAddress(String userId) {
        ExpressAddressInfo addressInfo = expressAddressInfoDao.getUserDefaultAddress(userId);
        if (addressInfo == null) {
            addressInfo = expressAddressInfoDao.getUserNewestAddress(userId);
        }
        if (addressInfo == null) {
            return null;
        } else {
            List<String> express = new ArrayList<>();
            express.add(addressInfo.getUserName());
            express.add(addressInfo.getPhone());
            String address = addressInfo.getProvince() + " " + addressInfo.getCity() + " " + addressInfo.getCounty()
                    + " " + addressInfo.getStreet();
            express.add(address);
            express.add(addressInfo.getDefaultAddress().toString());
            express.add(addressInfo.getAreaCode());
            return express;
        }
    }
}
